	function blendRangeFunc(temp){

		for(i=0; i< temp.childNodes.length; i++){
			if(temp.childNodes[i].nodeType == 1){
				tempContent = document.createTextNode(temp.childNodes[i].textContent);
				temp.replaceChild(tempContent, temp.childNodes[i])	
			}
		}
		
		return temp;		
		
	}

$(document).bind("ready", function(){
	
	var action = false;
	

	
	function removeEmptySpans(){
				$("span").each(function(){
					if(this.textContent == ''){
						$(this).remove();	
					}												
				});		
	}
	
	member1 = function(styleName, val, arr){
		
		if(styleName == "textDecoration"){
		
			for(i=0; i< arr.length; i++){
				if(isTextDecoration(arr[i], val)){
					return false;
				}
			}
			
			return true;
		} else {
		
			for(i=0; i<arr.length; i++){
				if(arr[i] == val){
					return true;	
				}
			}
			return false;
		
		}
	}
	
	member = function(p, v, arr){
			if(v){
			} else {
				for(i=0; i<arr.length; i++){
					if(arr[i] == p){
						return true;	
					}
				}
			
			}		
			return false;
	}
	
	removeDupChildrenSpan= function(){
		styleArray = ["font-weight", "font-style", "text-decoration"]
		
		$("span").each(function(){
			var same = true;
			
			if(this.parentNode.nodeName == "SPAN"){
				
				for(i=0; i< styleArray.length; i++){
					if($(this).css(styleArray[i]) != $(this).parent().css(styleArray[i])){
						same = false;	
					}
				}	
				
				if(same){
					$(this.childNodes).unwrap(this);	
				}
			
			}
		});		
	}
	
	removeDupAdjSibSpan=function(){
		styleArray = ["font-weight", "font-style", "text-decoration"]
		$("span").each(function(){
			if(this.nextSibling && this.nextSibling.nodeType == 1){
				var same = true;
				
				if(this.getElementsByTagName("span").length != 0 && this.nextSibling.getElementsByTagName("span").length != 0){
					same = false;	
				}
				
				
				
				for(i=0; i< styleArray.length; i++){
					if($(this).css(styleArray[i]) != $(this.nextSibling).css(styleArray[i])){
						same = false;	
					}
				}	
				
				if(same){
					var content = this.innerHTML + this.nextSibling.innerHTML;
					
					$(this.nextSibling).remove();
					
					this.innerHTML = content;
					
				}
			}
		});		
	}
	
	cleanSpans = function(){
				removeEmptySpans();
				removeDupChildrenSpan();
				removeDupAdjSibSpan();
	}
	
	
	function determineCommonRanges(temp, style, value){
		for(i=1; i<temp.childNodes.length-1; i++){
			if($(temp.childNodes[i]).css(style) != value){
				return 0;	
			}
		}	
		return 1;
	}
	
	butter ={};
	butter.buttonState ={
		"boldButton": 0,
		"italicButton": 0,
		"underlineButton": 0,
		"strikethroughButton": 0
	}
	
	butter.button_Match = {
		"font-weight": 700,
		"font-style": "italic"	
	}
	
	butter.buttonMatchOn = {
		"boldButton": 700,
		"italicButton": "italic",
		"underlineButton": "underline",
		"strikethroughButton": "line-through"
	}
	
	butter.buttonMatchOff = {
		"boldButton": 400,
		"italicButton": "normal",
		"underlineButton": "none",
		"strikethroughButton": "none"
	}
	
	butter.buttons = {
		"boldButton": "font-weight",
		"italicButton": "font-style",
		"underlineButton": ["text-decoration", "underline"],
		"strikethroughButton": ["text-decoration", "line-through"]
	}
	
	butter.buttonConvert = {
		"boldButton": "fontWeight",
		"italicButton": "fontStyle",
		"underlineButton": "textDecoration",	
		"strikethroughButton": "textDecoration"
	}
	
	butter.button_MatchOff = {
		"font-weight": 400,
		"font-style": "normal",
		"text-decoration": "none"
	}
	
	butter.buttonOnStates = {
		"boldButton": [700, "bold"],
		"italicButton": ["italic"],
		"underlineButton": ["underline"],
		"strikethroughButton": ["line-through"]

	}
	
	butter.buttonOffStates = {
		"boldButton": [400, "normal"],
		"italicButton": ["normal"],
		"underlineButton": ["none"],
		"strikethroughButton": ["none"]
	}
	
	state = {
		mousedown: false
	}
	
	// Assign data to buttons
	for(c in butter.buttons){
		if((typeof butter.buttons[c]) == "string"){
			$("#" + c).data("styleName", butter.buttons[c])
		} else {
			$("#" + c).data("styleName", butter.buttons[c][0])	
			$("#" + c).data("styleValue", butter.buttons[c][1])	
		}
	}
})